package dryworks.jsf.examples.generator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GeneratorStringUtils {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String s = "abCdeFgsjh dfbgxd";
		System.out.println(seperateHungarianNotatedWord(s));

	}

	public static String getAttrStaticVarName(String attrName) {
		return "ATTR_"+attrName.toUpperCase();
	}
	public static String seperateHungarianNotatedWord(String source) {

		try {
			if (source == null) {
				return null;
			}
			StringBuffer temp = new StringBuffer(source.substring(0, 1));
			Pattern p = Pattern.compile("[A-Z]");
			for (int i = 1; i < source.length(); i++) {
				Matcher m = p.matcher(source.substring(i, i + 1));
				if (m.matches()) {
					temp.append(" ").append(source.substring(i, i + 1));
				} else {
					temp.append(source.substring(i, i + 1));
				}
			}
			return temp.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return source;
		}
	}

	public static String upFirstLetter(String propName) {
		return propName.substring(0, 1).toUpperCase() + propName.substring(1);
	}

	public static String lowFirstLetter(String s) {
		return s.substring(0, 1).toLowerCase() + s.substring(1);
	}

}
